package common.utils;


public class PaginationUtil {

	private static int numLimit = 6;

	public static String getPaginationStyle(Page page,String url){
		String pagination="";
		if(page.getTotalPage()==0){
			pagination = "暂无记录";
		}else if(page.getTotalPage()==1){
			pagination+="<span>&nbsp;共"+page.getTotalCount()+"条数</span><a class=\"active\" href=\"javascript:;\"><b>1</b></a>";
		}else{
			if(url.indexOf("?")==-1)
			{
				pagination=getPagination("?",page,url,pagination,"#zkdp",1);//#zkdp为首页点评，1为首页点评分页样式，不提供跳转
				}
			else
			{
				pagination=getPagination("&",page,url,pagination,"#zkdp",1);
				}
		}
		return pagination;
	}
	/**
	 * 
	 * @param page
	 * @param url
	 * @param style
	 * @return
	 */
	public static String getPaginationStyleTwo(Page page,String url){
		String pagination="";
		if(page.getTotalPage()==0){
			pagination = "暂无记录";
		}else if(page.getTotalPage()==1){
			pagination+="<span>&nbsp;共"+page.getTotalCount()+"条数</span><a class=\"active\" href=\"javascript:;\"><b>1</b></a>";
		}else{
			if(url.indexOf("?")==-1)
			{
				pagination=getPagination("?",page,url,pagination,"",0);
				}
			else
			{
				pagination=getPagination("&",page,url,pagination,"",0);
				}
		}
		return pagination;
	}
	
	private static String getPagination(String symbol,Page page,String url,String pagination,String indexPage,int indexStyle){
		//首页
				if(page.getCurrentPage()==1){
					pagination = "<a class=\"backpage grey\">上页</a>";
					pagination+="<a class=\"active\" href=\"javascript:;\"><b>1</b></a>";
				}else{
					pagination = "<a class=\"backpage\" href='"+url+symbol+"current="+(page.getCurrentPage()-1)+indexPage+"'>上页</a>";
					pagination += "<a href='"+url+symbol+"current=1"+indexPage+"'><b>1</b></a>";
				}
				
				//处理前面的部分
				int start =  page.getCurrentPage()-numLimit/2;
				if(start>1){
					pagination += "<a class=\"shenlue\" href=\"javascript:void(0)\">...</a>";
					start = start+1;
				}else{
					start = 2;
				}
				
				//处理后面的分页部分
				int end = page.getCurrentPage()+numLimit/2-1;
				if(end>=page.getTotalPage()){
					end = page.getTotalPage()-1;
				}
				
				//处理中间的分页部分
				for(int i=start;i<=end;i++){
					if(page.getCurrentPage()==i){
						pagination+="<a class=\"active\" href=\"javascript:;\"><b>"+i+"</b></a>";
					}else{
						pagination+="<a href='"+url+symbol+"current="+i+indexPage+"'><b>"+i+"</b></a>";
					}
				}
				
				//处理后面的分页部分
				if((page.getCurrentPage()+numLimit/2)<page.getTotalPage()){
					pagination += "<a class=\"shenlue\" href=\"javascript:void(0)\">...</a>";
				}
				
				//末页
				if(page.getCurrentPage()==page.getTotalPage()){
					pagination+="<a class=\"active\" href=\"javascript:;\"><b>"+page.getTotalPage()+"</b></a>";
				    pagination+="<a class=\"nextpage greys\">下页</a>";
				}else{
					pagination+= "<a href='"+url+symbol+"current="+page.getTotalPage()+indexPage+"'><b>"+page.getTotalPage()+"</b></a>";
					pagination+="<a class=\"nextpage\" href='"+url+symbol+"current="+(page.getCurrentPage()+1)+indexPage+"'>下页</a>";
				}
				if(indexStyle==0)
				return pagination+="<span>&nbsp;共"+page.getTotalCount()+"条数据&nbsp;</span>转到第<input type=\"text\" id=\"cp\" value='"+page.getCurrentPage()+"' class=\"pageinput\">页<input type=\"hidden\" id=\"jumpurl\" value='"+url+"'/><input type=\"button\" value=\"跳转\"  class=\"pagebtn\" onclick=\"url();\"/>";
				else
				return pagination;
	
	}
}
